<!-- 确定中标人 -->
<template>
    <div class="app-container">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain size="mini" :disabled="single" @click="handleUpdate" v-if="checked==0">确定中标人</el-button>
            </el-col>
            <right-toolbar @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="candidateList" @selection-change="handleSelectionChange"
            :default-sort="{ prop: 'ranking', order: 'ascending' }">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" type="index" align="center" />
            <el-table-column label="序号" type="index" prop="hId" align="center" v-if="false" />
            <el-table-column label="供应商名称" align="center" prop="hName" />
            <el-table-column label="最终报价(万元)" align="center" prop="finalOffer">
                <template slot-scope="scope">
                    {{ scope.row.finalOffer / 10000 }}
                </template>
            </el-table-column>
            <el-table-column label="最终得分" align="center" prop="finalScore" sortable />
            <el-table-column label="是否推荐" align="center" prop="recommend">
                <template slot-scope="scope">
                    <span>{{ scope.row.recommend == 0 ? "是" : "否" }}</span>
                </template>
            </el-table-column>
            <el-table-column label="排名" align="center" prop="ranking" sortable />
            <el-table-column label="是否中标" align="center" prop="bidder">
                <template slot-scope="scope">
                    <span>{{ scope.row.bidder == 0 ? "是" : "否" }}</span>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import {
    getBidWinningCandidate,
    confirmWinningBidder,
    
} from "@/api/system/purchase.js";

export default {
    name: "",
    data() {
        return {
            startTime: "",
            endTime: "",
            checked: 0,
            status: false,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 中标候选人表格数据
            candidateList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                iNumber: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {},
        };
    },
    methods: {
        handleSelectionChange(selection) {
            this.ids = selection;
            this.single = selection.length !== 1;//只能选中一个
            this.multiple = !selection.length;
        },
        getList() {
            getBidWinningCandidate(this.queryParams.iNumber).then((res) => {
                this.loading = false;
                this.candidateList = res.data.candidate;
                this.startTime = res.data.csTender.startTime;
                this.endTime = res.data.csTender.endTime;
                res.data.candidate.forEach((ele) => {
                    if (ele.bidder == 0) {
                        return (this.checked = 1);
                    }
                });
            });
        },
        handleUpdate() {
            if (this.ids.length == 0) {
                this.$message({
                    type: "warning",
                    message: "请选择中标人!",
                });
                return;
            }
            const start = new Date(this.startTime);
            const end = new Date(this.endTime);
            const date = new Date();
            if (date < start || (date > start && date < end)) {
                this.$message({
                    type: "error",
                    message: "当前时间不可确定中标人",
                });
                return false;
            }
            this.$confirm(
                "一旦确认中标人后,后续无法再次更改,请仔细核对!!!是否继续?",
                "提示",
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            ).then(() => {
                this.ids[0].iNumber = this.queryParams.iNumber;
                confirmWinningBidder(this.ids).then(res => {
                    if (res.data > 0) {
                        this.$message({
                            type: 'success',
                            message: '确认成功!'
                        });
                        this.getList();
                    }
                })
            });
        },
    },
    mounted() {
        this.queryParams.iNumber = this.$route.query.iNumber;
        this.getList();
        console.log(this.$route.query,"这是测试路由中的参数");
    },
};
</script>
<style scoped>
.clearfix:before,
.clearfix:after {
    display: table;
    content: "";
}

.clearfix:after {
    clear: both;
}

.box-card {
    width: 50%;
    margin-left: 28%;
}
</style>
